package org.springframework.study;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Import;
import org.springframework.study.bean.User;

import java.util.Collection;
import java.util.Map;

@Import({
		org.springframework.study.config.AnnotationBeanConfiguration.class
})
public class AnnotationTest {

	@Autowired
	@Qualifier("user1")
	private User user;

	@Autowired
	private Map<String, User> userMap;

	@Autowired
	private Collection<User> userCollection;

	private User userFromCtor;

	public AnnotationTest(@Autowired @Qualifier("user2") User userFromCtor) {
		this.userFromCtor = userFromCtor;
	}

	private User userFromMethod;

	@Autowired
	@Qualifier("user1")
	public void autowiredUser(User user) {
		this.userFromMethod = user;
	}


	public static void main(String[] args) {

		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
		context.register(AnnotationTest.class);

		context.refresh();

		AnnotationTest demo = context.getBean(AnnotationTest.class);

		System.out.println("demo.user : " + demo.user);
		System.out.println("demo.userMap : " +demo.userMap);
		System.out.println("demo.userCollection : " +demo.userCollection);
		System.out.println("demo.userFromConstructor : " +demo.userFromCtor);
		System.out.println("demo.userFromMethod : " +demo.userFromMethod);
//		System.out.println("demo.userFromCustomAnnotation : " +demo.userFromCustomAnnotation);
		context.close();
	}


}
